package fr.pud.client.view.mapstation;

import javax.swing.ImageIcon;

import fr.pud.client.images.ImagesDatabase;
import fr.pud.utils.Tools;

/**
 * This class implements the singleton pattern to be sure that only one
 * background is going to be mapped in the memory.
 * It enables to save some memory for the other applications
 * @author Pierre Reliquet
 */
public class BubbleBackground {
    /**
     * An image of a bubble where the adress will be written
     */
    private static BubbleBackground singleton = null;
    /**
     * The background
     */
    private static ImageIcon        imageBubble;

    /**
     * @return the height of the background
     */
    public static final int getHeight() {
        initialization();
        return imageBubble.getIconHeight();
    }

    /**
     * @return the unique imageIcon instantiated
     */
    public static final ImageIcon getImageIcon() {
        initialization();
        return imageBubble;
    }

    /**
     * @return the width of the background
     */
    public static final int getWidth() {
        initialization();
        return imageBubble.getIconWidth();
    }

    /**
     * The method which tests if the singleton has already been implemented.
     */
    private static void initialization() {
        if (singleton == null) {
            singleton = new BubbleBackground();
        }
    }

    /**
     * The private constructor to be sure that no other instance can be
     * instantiated
     */
    private BubbleBackground() {
        try {
            imageBubble = ImagesDatabase.BUBBLE;
        }
        catch (Exception e) {
            Tools.writeToLogFile("Error while reading bubble_final.png",
                    Tools.LOG_FILE_NO_JOPTION_PANE, e.getStackTrace());
        }
    }
}
